

************************
** Study 2: Figure S2.19
************************



** 2017 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 pol_interest4 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2015_1 vote2015_2 vote2015_3 vote2015_4 vote2015_5 vote2015_6 vote2015_7 vote2015_8 vote2015_9 vote2015_10 refvote2016_1 refvote2016_2 refvote2016_3 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2017.dta", replace

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' postattack if statadate == td(02jun2017) | statadate == td(04jun2017)
estimates store `dv'1
reg `dv' postattack if inrange(statadate,td(01jun2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(05jun2017))
estimates store `dv'2
reg `dv' postattack if inrange(statadate,td(31may2017),td(02jun2017)) | inrange(statadate,td(04jun2017),td(06jun2017))
estimates store `dv'3
}

* Results table
gen days = _n in 1/3
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen pe_`dv' = .
gen se_`dv' = .
gen p_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'
replace n_`dv' = `e(N)' if days == `i'
estimates replay `dv'`i'
matrix R = r(table)
replace pe_`dv' = R[1,1] if days == `i'
replace se_`dv' = R[2,1] if days == `i'
replace p_`dv' = R[4,1] if days == `i'
replace ll_`dv' = R[5,1] if days == `i'
replace ul_`dv' = R[6,1] if days == `i'
replace d_`dv' = pe_`dv'/sd_`dv' if days == `i'
replace dlow_`dv' = pe_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv' if days == `i'
replace dup_`dv' = pe_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv' if days == `i'
}
}

drop newid - referrer
drop _est*
keep in 1/3
gen year = 2017
order year

save "NoControls2017.dta", replace	




** 2019 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2017_1 vote2017_2 vote2017_3 vote2017_4 vote2017_5 vote2017_6 vote2017_7 vote2017_8 vote2017_9 vote2017_10 vote2017_11 refvote2016_1 refvote2016_2 refvote2016_3 refvote2016_4 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2019.dta", replace

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' postattack if statadate == td(28nov2019) | statadate == td(30nov2019)
estimates store `dv'1
reg `dv' postattack if inrange(statadate,td(27nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(1dec2019))
estimates store `dv'2
reg `dv' postattack if inrange(statadate,td(26nov2019),td(28nov2019)) | inrange(statadate,td(30nov2019),td(2dec2019))
estimates store `dv'3
}

* Results table
gen days = _n in 1/3
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen pe_`dv' = .
gen se_`dv' = .
gen p_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
forvalues i = 1/3 {
estimates restore `dv'`i'
replace n_`dv' = `e(N)' if days == `i'
estimates replay `dv'`i'
matrix R = r(table)
replace pe_`dv' = R[1,1] if days == `i'
replace se_`dv' = R[2,1] if days == `i'
replace p_`dv' = R[4,1] if days == `i'
replace ll_`dv' = R[5,1] if days == `i'
replace ul_`dv' = R[6,1] if days == `i'
replace d_`dv' = pe_`dv'/sd_`dv' if days == `i'
replace dlow_`dv' = pe_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv' if days == `i'
replace dup_`dv' = pe_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv' if days == `i'
}
}

drop id - region3
drop _est*
keep in 1/3
gen year = 2019
order year

save "NoControls2019.dta", replace





** Figure
*********


* Bring data in correct shape
foreach y in 2017 2019 { 
use "NoControls`y'.dta", replace
set obs 15
sum year
replace year = `r(mean)'
gen row = _n
gen outcome = ""
gen pe = .
gen ll = .
gen ul = .
gen n = .
forvalues i = 1/3 {
	replace outcome = "sec" if row == `i' + 3
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 3
	sum d_sec if row == `i'
	replace pe = `r(mean)' if row == `i' + 3
	sum dlow_sec if row == `i'
	replace ll = `r(mean)' if row == `i' + 3
	sum dup_sec if row == `i'
	replace ul = `r(mean)' if row == `i' + 3
	sum n_sec if row == `i'
	replace n = `r(mean)' if row == `i' + 3
}
forvalues i = 1/3 {
	replace outcome = "imm" if row == `i' + 6
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 6
	sum d_imm if row == `i'
	replace pe = `r(mean)' if row == `i' + 6
	sum dlow_imm if row == `i'
	replace ll = `r(mean)' if row == `i' + 6
	sum dup_imm if row == `i'
	replace ul = `r(mean)' if row == `i' + 6
	sum n_imm if row == `i'
	replace n = `r(mean)' if row == `i' + 6
}
forvalues i = 1/3 {
	replace outcome = "britid" if row == `i' + 9
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 9
	sum d_britid if row == `i'
	replace pe = `r(mean)' if row == `i' + 9
	sum dlow_britid if row == `i'
	replace ll = `r(mean)' if row == `i' + 9
	sum dup_britid if row == `i'
	replace ul = `r(mean)' if row == `i' + 9
	sum n_britid if row == `i'
	replace n = `r(mean)' if row == `i' + 9
}
forvalues i = 1/3 {
	replace outcome = "englid" if row == `i' + 12
	sum days if row == `i'
	replace days = `r(mean)' if row == `i' + 12
	sum d_englid if row == `i'
	replace pe = `r(mean)' if row == `i' + 12
	sum dlow_englid if row == `i'
	replace ll = `r(mean)' if row == `i' + 12
	sum dup_englid if row == `i'
	replace ul = `r(mean)' if row == `i' + 12
	sum n_englid if row == `i'
	replace n = `r(mean)' if row == `i' + 12
}
drop in 1/3
drop n_sec - row
save temp`y'.dta, replace
}

* Merge 2017 and 2019
use temp2017.dta, replace
append using temp2019.dta

* Graph preparations
gen ntext = "{it:N} = "
tostring n, replace
replace ntext = ntext + n
gen ypos = .
replace ypos = 0.70 if days == 1
replace ypos = 0.50 if days == 2
replace ypos = 0.30 if days == 3
replace ypos = ypos + 3 if outcome == "sec"
replace ypos = ypos + 2 if outcome == "imm"
replace ypos = ypos + 1 if outcome == "britid"
gen x = 0.30

* Graph
twoway ///
	(scatter ypos pe if days == 1, mcolor(gs12) msymbol(o) msize(medium)) ///
	(rspike ll ul ypos if days == 1, lcolor(gs12) horizontal) ///
	(scatter ypos pe if days == 2, mcolor(gs7) msymbol(s) msize(medium)) ///
	(rspike ll ul ypos if days == 2, lcolor(gs7) horizontal) ///
	(scatter ypos pe if days == 3, mcolor(gs2) msymbol(t) msize(medium)) ///
	(rspike ll ul ypos if days == 3, lcolor(gs2) horizontal) ///
	(scatter ypos x, msymbol(none) mlabel(ntext) mlabsize(vsmall) mlabangle(horizontal) mlabposition(3)) ///
	, ///
	by(year, noixlabel ixtitle graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("{it:Note:} The spikes represent 95% confidence intervals.") legend(pos(6))) ///
	ytitle("") yscale(noline range(0 4)) ///
	ylabel(3.5 "Tough security" 2.5 "Anti-immigration" 1.5 "British identity" 0.5 "English identity", angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes (Cohen's {it:d})", margin(small))  ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	xlabel(-0.10(.10).40,) xmlabel(-0.10(0.05)0.40, ) xscale(noline) ///
	legend(order(1 3 5) label(1 "± 1 day") label(3 "± 2 days") label(5 "± 3 days") rows(1) size(small) keygap(*1) region(lstyle(none) lcolor(white))) ///
	subtitle(, size(large) align(middle) margin(bottom) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	scheme(s2mono) xsize(6) ysize(3.5)
gr_edit .b1title.draw_view.setstyle, style(no)
gr_edit .plotregion1.xaxis1[1].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy
gr_edit .legend.DragBy 0 12
gr_edit .gmetric_mult = 1.15





** Tidy Up
**********

erase "NoControls2017.dta"
erase "NoControls2019.dta"
erase temp2017.dta
erase temp2019.dta

